/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.PayBillItemDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class PayBillItemDaoImpl extends BaseDaoImpl implements PayBillItemDao {
	public List getListByPayBill(long billId) {
		String sql = "from com.minierp.model.PayBillItem s where s.billId="
				+ billId + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getList(long billId, String payType) {
		String sql = "select b,s from com.minierp.model.PayBill b ,com.minierp.model.PayBillItem s where b.id=s.billId and s.purchaseBillId="
				+ billId
				+ " and b.payType=\'"
				+ payType
				+ "\'"
				+ " and b.enabled=\'Y\'" + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.PayBillItem where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}

	public int deleteByPayBillId(final long billId) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.PayBillItem where billId=:billId";
						return new Integer(session.createQuery(hql)
								.setLong("billId", billId).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}